package com.oocl.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.oocl.entity.DeliverInfo;
import com.oocl.service.DeliverInfoService;

@Controller
public class AddressController {
	@Resource(name="deliverInfoService")
	private DeliverInfoService deliverInfoService;
	
	@ResponseBody
	@RequestMapping(value="/allDeliver",method={RequestMethod.GET})
	public List<DeliverInfo> allDeliver(HttpSession sen){
		String cid = (String) sen.getAttribute("cid");
		List<DeliverInfo> addressList = deliverInfoService.loadAllDeliverInfoByCid(cid);
		return addressList;
	}
	
	
	@ResponseBody
	@RequestMapping(value="/addDeliver",consumes="application/json",method={RequestMethod.POST})
	public DeliverInfo addDeliver(@RequestBody DeliverInfo deliverInfo, HttpSession sen){
		String cid = (String) sen.getAttribute("cid");
		DeliverInfo address = deliverInfoService.addDeliverInfo(deliverInfo,cid);
		return address;
	}
	@ResponseBody
	@RequestMapping(value="/delDeliver",method=RequestMethod.DELETE)
	public String delDeliver(String did){
		deliverInfoService.deleteDeliverInfo(did);
		return "{}";
	}
	@ResponseBody
	@RequestMapping(value="/updateDeliver",method=RequestMethod.PUT,consumes="application/json")
	public DeliverInfo updateDeliver(@RequestBody DeliverInfo d){
		
		DeliverInfo dInfo = deliverInfoService.transformDeliverInfo(d);
		return deliverInfoService.updateDeliverInfo(dInfo);
	}
	
	
}
